/*
 * Powered By 
 * Since 2010 - 2016
 */

package com.rf.business.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import com.rf.sys.utils.PageUtils;
import com.rf.sys.utils.ConfigUtils;
import com.rf.sys.dao.SqlAdapterMapper;
import com.rf.business.dao.DispalyCardMapper;
import com.rf.business.model.DispalyCard;
import com.rf.business.model.DispalyCardExample;
import com.rf.business.service.DispalyCardService;

@Service("dispalyCardService")
public class DispalyCardServiceImpl implements DispalyCardService {
	
	@Autowired
   	private SqlAdapterMapper sqlAdapterMapper;//注入dao
   	@Autowired
   	private DispalyCardMapper dispalyCardMapper;//注入dao

   	/**
	 * 根据id获取数据
	 * @param dispalyCardId
	 * @return DispalyCard
	 */
   	@Override
	public DispalyCard getDispalyCardByID(String id
) throws Exception{
		// TODO Auto-generated method stub
		return dispalyCardMapper.selectByPrimaryKey(id
);
	}
	
	/**
	 * 根据DispalyCard获取数据
	 * @param DispalyCard
	 * @return List<DispalyCard>
	 */
	@Override
	public List<DispalyCard> getDispalyCard(DispalyCard dispalyCard) throws Exception{
		// TODO Auto-generated method stub
		DispalyCardExample example = new DispalyCardExample();
		com.rf.business.model.DispalyCardExample.Criteria criteria= example.createCriteria();
		
		//criteria.andStateNotEqualTo(ConfigUtils.DELSTATE);//不查询已删除的
		List<DispalyCard> list = dispalyCardMapper.selectByExample(example);
		return list;
	}
	
	/**
	 * 获取所有数据
	 * @param 
	 * @return List<DispalyCard>
	 */
	@Override
	public List<DispalyCard> getDispalyCard() throws Exception{
		// TODO Auto-generated method stub
		DispalyCardExample example = new DispalyCardExample();
		com.rf.business.model.DispalyCardExample.Criteria criteria= example.createCriteria();
		
		//criteria.andStateNotEqualTo(ConfigUtils.DELSTATE);//不查询已删除的
		return dispalyCardMapper.selectByExample(example);
	}
   	
	/**
	 * 保存信息
	 * @param DispalyCard
	 * @return
	 */
	@Override
	public void addDispalyCard(DispalyCard dispalyCard) throws Exception{
		// TODO Auto-generated method stub
		dispalyCardMapper.insert(dispalyCard);
	}

	/**
	 * 修改数据
	 * @param DispalyCard
	 * @param
	 */
	@Override
	public void updateDispalyCard(DispalyCard dispalyCard) throws Exception{
		// TODO Auto-generated method stub
		dispalyCardMapper.updateByPrimaryKeySelective(dispalyCard);
	}
	
	/**
	 * 删除数据
	 * @param dispalyCardId
	 * @param
	 */
	@Override
	public void deleteDispalyCard(String id
) throws Exception{
		// TODO Auto-generated method stub
		dispalyCardMapper.deleteByPrimaryKey(id
);
	}

	/**
	 * 获取数据分页
	 * @param DispalyCard
	 * @param pageUtils
	 * @return Map
	 */
	@Override
	public Map getDispalyCardPage(DispalyCard dispalyCard,PageUtils pageUtils) throws Exception{
		DispalyCardExample example = new DispalyCardExample();
		com.rf.business.model.DispalyCardExample.Criteria criteria= example.createCriteria();
		
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		//下一条执行语句，即为要被转换的语句
		List<DispalyCard> list = dispalyCardMapper.selectByExample(example);
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
}

